home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2005 March
/
CMCD0305.ISO
/
Software
/
Shareware
/
Comunicatii
/
TrafMeter5
/
TrafMeter56.exe
/
{app}
/
XSLExamples
/
month.xsl
next >
Wrap
Extensible Markup Language
|
2004-08-07
|
13KB
|
514 lines
<?xml version="1.0"?>
<xsl:template xmlns:xsl="uri:xsl">
<script>
//
// Version 1.3.
// Copyright (c) 2003 Alexey Kazakovsky.
//
</script>
<style>
A { text-decoration: none; }
A:HOVER { color: red; text-decoration: underline; }
h2.x { font-family: Arial,Verdana; font-size:14pt; };
h3.x { font-family: Arial,Verdana; font-size:12pt; };
p.x { font-family: Arial,Verdana; font-size:10pt; };
td.a0 { background-color:#F0F0F0; border-top:1px solid black; border-left:1px solid black; border-bottom:1px solid black; border-right:1px solid black; font-family: Arial,Verdana; font-size:10pt; text-align:left; margin-left:13pt; margin-right:3pt; }
td.h0 { background-color:#F0F0F0; border-top:1px solid black; border-left:1px solid black; border-bottom:1px solid black; font-family: Arial,Verdana; font-size:10pt; text-align:left; margin-left:13pt; margin-right:3pt; }
td.h1 { background-color:#F0F0F0; border-top:1px solid black; border-left:1px solid black; border-right:1px solid black; border-bottom:1px solid black; font-family: Arial,Verdana; font-size:10pt; margin-left:3pt; margin-right:3pt; }
td.t { font-family: Arial,Verdana; font-size:10pt; text-align:left; margin-left:3pt; margin-right:3pt; }
td.t0 { border-left:1px solid black; background:#FFFFFF; border-bottom:1px solid black; font-family: Arial,Verdana; font-size:10pt; text-align:left; margin-left:3pt; margin-right:3pt; }
td.t1 { border-left:1px solid black; border-right:1px solid black; border-bottom:1px solid black; font-family: Arial,Verdana; font-size:10pt; margin-left:3pt; margin-right:3pt; }
</style>
<html>
<body link="#0000FF" vlink="#0000FF">
<script>
var expDays = 30;
var expTime = new Date();
expTime.setTime(expTime.getTime() + (expDays * 24 * 60 * 60 * 1000));
var day_cookie = 'report_day';
var filter_cookie = 'report_filter';
var unit_cookie = 'report_unit';
var Unit=0;
var Filter=0;
var FilterName='All';
var Year=0;
var Month=0;
var Day=0;
var DayIndex=0;
// The array "Days" will be used to construct
// a list of available days from XML Traffic Report
var Days=new Array(32); i=0;
while (i!=32)
{
Days[i]="0";
i++;
};
// This function formats a traffic counter (cnt) for given traffic unit:
// unit_no==0 - Bytes
// unit_no==1 - KBytes
// unit_no==2 - MBytes
// unit_no==3 - GBytes
function FormatCounter(cnt,unit_no)
{
var result=''; var t;
if (unit_no==0) { result=cnt; };
if (unit_no==1) { t=cnt/1024; t=t*10; t=Math.floor(t); t=t/10; result=t+' Kb'; };
if (unit_no==2) { t=cnt/1048576; t=t*100; t=Math.floor(t); t=t/100; result=t+' Mb'; };
if (unit_no==3) { t=cnt/1073741824; t=t*1000; t=Math.floor(t); t=t/1000; result=t+' Gb'; };
return result;
};
function getMonthAsStr(month_no)
{
if (month_no==1) return 'January';
if (month_no==2) return 'February';
if (month_no==3) return 'March';
if (month_no==4) return 'April';
if (month_no==5) return 'May';
if (month_no==6) return 'June';
if (month_no==7) return 'July';
if (month_no==8) return 'August';
if (month_no==9) return 'September';
if (month_no==10) return 'October';
if (month_no==11) return 'November';
if (month_no==12) return 'December';
return 'null';
};
// This function is like sprintf(result,"%02d",param_no);
function format_02d(param_no)
{
var result=''; var q=Math.floor((param_no/10));
if (q==0) result='0'; result=result+param_no;
return result;
};
function getDateFromYYMMDD(yymmdd)
{
var result='';
var myYear=2000+(Math.floor((yymmdd/10000)));
var myMonth=Math.floor((yymmdd%10000)/100);
var myDay=yymmdd%100;
result=getMonthAsStr(myMonth)+', '+format_02d(myDay)+' ';
return result;
};
// name - name of the cookie
// * return string containing value
// of specified cookie or null if cookie
// does not exist
function getCookie(name)
{
var prefix = name + "="
var cookieStartIndex = document.cookie.indexOf(prefix)
if (cookieStartIndex == -1)
return null
var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex +
prefix.length)
if (cookieEndIndex == -1)
cookieEndIndex = document.cookie.length
return unescape(document.cookie.substring(cookieStartIndex +
prefix.length,
cookieEndIndex))
}
function setCookie(name, value)
{
var argv = setCookie.arguments;
var argc = setCookie.arguments.length;
var expires=null;
var path=null;
var domain=null;
var secure=false;
argc=argc-2;
if (argc!=-1)
if (argc!=0)
{
expires=argv[2]; argc--;
if (argc!=0)
{
path=argv[3]; argc--;
if (argc!=0)
{
domian=argv[4]; argc--;
if (argc!=0) secure=argv[5];
};
};
};
document.cookie = name + "=" + escape(value) +
((expires == null)? "": ("; expires=" + expires.toGMTString())) +
((path == null)? "": ("; path=" + path)) +
((domain == null)? "": ("; domain=" + domain)) +
((secure == true)? "; secure": "");
}
function deleteCookie(name)
{
var expTime = new Date();
expTime.setTime(expTime.getTime() - 1);
var cval = getCookie(name);
document.cookie = name + "=" + cval + "; expires=" + expTime.toGMTString();
}
function change_day(Index)
{
Day=select_day.options[Index].value;
setCookie(day_cookie,Day);
setCookie(filter_cookie,0);
setCookie(unit_cookie,Unit);
document.location.reload();
};
function change_filter(Index)
{
Filter=Index;
setCookie(filter_cookie,Filter);
setCookie(day_cookie,0);
setCookie(unit_cookie,Unit);
document.location.reload();
};
function change_fullreport()
{
setCookie(unit_cookie,Unit);
setCookie(filter_cookie,0);
setCookie(day_cookie,0);
document.location.reload();
};
function change_unit(Index)
{
setCookie(unit_cookie,Index);
setCookie(filter_cookie,Filter);
setCookie(day_cookie,Day);
document.location.reload();
};
function out_tblheader(colname1,colname2,colname3,colname4)
{
document.write('<tr>');
document.write('<td class="h0"><B>');
document.write(colname1);
document.write('</B></td>');
document.write('<td class="h0"><B>');
document.write(colname2);
document.write('</B></td>');
document.write('<td class="h0"><B>');
document.write(colname3);
document.write('</B></td>');
document.write('<td class="h1"><B>');
document.write(colname4);
document.write('</B></td>');
document.write('</tr>');
};
Day=getCookie(day_cookie);
if (Day==-1) Day=0;
if (Day==null) Day=0;
deleteCookie(day_cookie);
Filter=getCookie(filter_cookie);
if (Filter==null) Filter=0;
deleteCookie(filter_cookie);
Unit=getCookie(unit_cookie);
if (Unit==null) Unit=0;
deleteCookie(unit_cookie);
</script>
<xsl:for-each select="TrafficReport/Filter/Day">
<script>
// This will make a list of avalaible days
// from monthly XML Traffic Reports.
var dt = parseInt("<xsl:value-of select="@dt"/>",10);
Year=Math.floor((dt/10000))+2000;
Month=Math.floor((dt%10000)/100);
dt=dt%100;
Days[dt]="1";
</script>
</xsl:for-each>
<xsl:for-each select="TrafficReport/Filter">
<script>
var f = parseInt("<xsl:value-of select="@Id"/>",10);
if (f==Filter) FilterName=new String('<xsl:value-of select="Name"/>');
</script>
</xsl:for-each>
<Script>
//
// Begin of output a top menu
//
</Script>
<table border="0" cellspacing="0" cellpadding="3">
<tr>
<td>
<table border="0" cellspacing="0" cellpadding="6">
<tr><td class="a0">
<a href="javascript:change_fullreport()">Full monthly report</a>
</td></tr>
</table>
</td>
<td>
<table border="0" cellspacing="0" cellpadding="3"><tr><td class="a0">
Report for the specific day
<select name="select_day" onchange="change_day(selectedIndex)" >
<option value="0">All days</option>
<script>
i=1; j=1;
while (i!=32)
{
if (Days[i]!="0")
{
if (Day==i) DayIndex=j;
document.write('<option value="');
document.write(i);
document.write('">');
document.write(i);
document.write('</option>');
j++;
};
i++;
};
select_day.selectedIndex=DayIndex;
</script>
</select>
</td></tr></table>
</td>
<td>
<table border="0" cellspacing="0" cellpadding="3">
<tr><td class="a0">
Show counters in
<select name="select_unit" onchange="change_unit(selectedIndex)" >
<option value="0">Bytes</option>
<option value="1">KBytes</option>
<option value="2">MBytes</option>
<option value="3">GBytes</option>
</select>
<script>
select_unit.selectedIndex=Unit;
</script>
</td></tr></table>
</td></tr></table>
<Script>
//
// End of output the top menu
//
</Script>
<H2 class="x">Your company name</H2>
<H3 class="x">Traffic report for:
<script>
document.write(getMonthAsStr(Month));
if (Day!=0)
{
document.write(', ');
document.write(format_02d(Day));
};
document.write(' ');
document.write(Year);
</script>
</H3>
<H3 class="x">
<script>
if (Filter==0)
{
document.write('Filters: All');
}
else
{
var str='Filter: '+FilterName+', FilterId='+Filter;
document.write(str);
};
</script>
</H3>
<script>
//
// Begin of output a table with counters
//
var header=0;
</script>
<table cellpadding="4" border="0" cellspacing="0">
<xsl:for-each select="TrafficReport/Filter">
<script>
if (Filter==0)
if (Day==0)
{
if (header==0)
{
out_tblheader('FilterId','Filter Name','Sent bytes','Recv bytes');
header=1;
};
document.write('<tr>');
document.write('<td class="t0">');
var f = parseInt("<xsl:value-of select="@Id"/>",10);
var s='<a href="javascript:change_filter('+f+')">'+f+'</a>';
document.write(s);
document.write('</td>');
document.write('<td class="t0">');
document.write('<xsl:value-of select="Name"/>');
document.write('</td>');
var sent=parseInt("<xsl:value-of select="Sent"/>",10);
var recv=parseInt("<xsl:value-of select="Recv"/>",10);
document.write('<td class="t0">');
document.write(FormatCounter(sent,Unit));
document.write('</td>');
document.write('<td class="t1">');
document.write(FormatCounter(recv,Unit));
document.write('</td>');
document.write('</tr>');
};
if (Filter==0)
if (Day!=0)
{
var dt='0'+(Year-2000)+format_02d(Month)+format_02d(Day);
if (header==0)
{
out_tblheader('FilterId','Filter Name','Sent bytes','Recv bytes');
header=1;
};
document.write('<tr>');
document.write('<td class="t0">');
var f = parseInt("<xsl:value-of select="@Id"/>",10);
var s='<a href="javascript:change_filter('+f+')">'+f+'</a>';
document.write(s);
document.write('</td>');
document.write('<td class="t0">');
document.write('<xsl:value-of select="Name"/>');
document.write('</td>');
var sent=0;
var recv=0;
<xsl:for-each select="Day">
var day_dt=parseInt("<xsl:value-of select="@dt"/>",10);
if (day_dt==dt)
{
sent=parseInt("<xsl:value-of select="Sent"/>",10);
recv=parseInt("<xsl:value-of select="Recv"/>",10);
};
</xsl:for-each>
document.write('<td class="t0">');
document.write(FormatCounter(sent,Unit));
document.write('</td>');
document.write('<td class="t1">');
document.write(FormatCounter(recv,Unit));
document.write('</td>');
document.write('</tr>');
};
if (Filter!=0)
if (Day==0)
{
if (header==0)
{
out_tblheader('FilterId','Day','Sent bytes','Recv bytes');
header=1;
};
var f = parseInt("<xsl:value-of select="@Id"/>",10);
if (f == Filter)
{
<xsl:for-each select="Day">
document.write('<tr>');
document.write('<td class="t0">');
document.write(f);
document.write('</td>');
var dayAttr=parseInt("<xsl:value-of select="@dt"/>",10);
document.write('<td class="t0">');
document.write(getDateFromYYMMDD(dayAttr));
document.write('</td>');
var sent=0;
var recv=0;
sent=parseInt("<xsl:value-of select="Sent"/>",10);
recv=parseInt("<xsl:value-of select="Recv"/>",10);
document.write('<td class="t0">');
document.write(FormatCounter(sent,Unit));
document.write('</td>');
document.write('<td class="t1">');
document.write(FormatCounter(recv,Unit));
document.write('</td>');
document.write('</tr>');
</xsl:for-each>
};
};
</script>
</xsl:for-each>
</table>
<p><br>
<i>Last Modified:
<xsl:value-of select="TrafficReport/LastModified"/>
</i></br>
</p>
</body></html>
</xsl:template>